//
//  PhotoAlbumView.swift
//  SwiftuiUno
//
//  Created by baozi on 2023/11/28.
//

import SwiftUI

struct PhotoAlbumPreView: View {
    @Binding var selectedImgIdx: Int
    @Binding var picDatas: [CaptureImageData]
    @Environment(\.presentationMode) var presentationMode
    var body: some View {  
        VStack {
            HStack(spacing: 10) {
                Image(systemName: "xmark")
                    .resizable()
                    .frame(width: 22, height: 22)
                    .foregroundColor(.gray)
                    .padding()
                    .onTapGesture {
                        presentationMode.wrappedValue.dismiss()
                    }
                Spacer()
            }
            TabView {
                ForEach(picDatas) { pic in
                    if let image = UIImage(data: pic.datas) {
                        Image(uiImage: image)
                            .resizable()
                            .aspectRatio(contentMode: .fill)
                            .cornerRadius(12)
                            .padding()
                    }
                }
            }
            .tabViewStyle(.page(indexDisplayMode: .always))
            .frame(maxWidth: .infinity, maxHeight: .infinity)
        }

    }
}

#Preview {
    PhotoAlbumPreView(selectedImgIdx: .constant(0), picDatas: .constant([]))
}
